//
//  ThumbView.m
//  CommentsTableView
//
//  Created by Gamefire on 16/4/21.
//  Copyright © 2016年 Gamefire. All rights reserved.
//

#import "ThumbView.h"
@interface ThumbView (){


    UIImageView *imageView;

}

@property (nonatomic,strong)UIButton *Thumbbutton;

@end
@implementation ThumbView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}

- (void)initUI{
    [self setBackgroundColor:[UIColor whiteColor]];
    UIImage *image = nil;
    _Thumbbutton = [[UIButton alloc] initWithFrame:CGRectMake(10, 13, 52, 28)];
    image = [UIImage imageNamed:@"Like"];
    [_Thumbbutton setImage:image forState:UIControlStateNormal];
    
    image = [UIImage imageNamed:@"yizan"];
    [_Thumbbutton setImage:image forState:UIControlStateNormal];
    
    image = [UIImage imageNamed:@""];
    [_Thumbbutton setImage:image forState:UIControlStateSelected];
    
    [_Thumbbutton addTarget:self action:@selector(TouchEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_Thumbbutton];

    UILabel *numberlabel = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 45, 21, 35, 12.5)];
    [numberlabel setBackgroundColor:[UIColor whiteColor]];
//    [numberlabel setText:@"1573"];
    [numberlabel setFont:[UIFont systemFontOfSize:13.0]];
    [numberlabel setTextColor:[UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1]];
    [self addSubview:numberlabel];
    
    for (int i = 5; i > 0; i--) {
        imageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_Thumbbutton.frame) - 30.0 + i *41.0, 13, 29, 29)];
        [imageView setBackgroundColor:[UIColor clearColor]];
        [imageView.layer setCornerRadius:29.0/2.0];
        [self addSubview:imageView];
    }

}
- (void)imageUrlStr:(NSString *)String{
//    [imageView setImage:String];
    [imageView setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:String]]]];
    
}


- (void)setSelect:(BOOL)select
{
    [_Thumbbutton setSelected:select];
    
}

- (void)TouchEvent:(UIButton *)sender{
    
    if ([_Thumbbutton isSelected])
    {
        [_Thumbbutton setSelected:NO];
        [_MThumbViewDelegate removeConnect];
    }
    else
    {
        [_Thumbbutton setSelected:YES];
        
        if (_MThumbViewDelegate && [_MThumbViewDelegate respondsToSelector:@selector(connectWork)])
        {
            [_MThumbViewDelegate connectWork];
        }
        
    }
    
//    UIButton *button = sender;
//    [button setImage:[UIImage imageNamed:@"yizan"] forState:UIControlStateNormal];
//    if (sender.selected == YES) {
//        [button setImage:[UIImage imageNamed:@"Like"] forState:UIControlStateNormal];
//    }
//    sender.selected = !button.selected;
}
@end
